package com.hxzy.common.util;

import com.hxzy.common.enums.AckCode;
import com.hxzy.common.vo.DictData;
import com.hxzy.exception.ServiceException;

import java.util.*;

/**
 * 通用字典的工具类
 * @author Administrator
 */
public class DictDataUtil {

    private static Map<String, List<DictData>>  dictMap=new HashMap<>();

    public static String SEX_TAG="sex";
    public static String STATE_TAG="status";
    public static String AUDIT_TAG="aduit";
    public static String ISGROUDING_TAG="isgrounding";

    static{
        //可变的数据类型-性别
        List<DictData> sexDictList=new ArrayList<>();
        sexDictList.add(new DictData(0,"女"));
        sexDictList.add(new DictData(1,"男"));
        //可变，变为不可变
        dictMap.put(SEX_TAG, Collections.unmodifiableList(sexDictList));

        //状态
        List<DictData> statusDictList=new ArrayList<>();
        statusDictList.add(new DictData(0,"正常"));
        statusDictList.add(new DictData(1,"停用"));
        //可变，变为不可变
        dictMap.put(STATE_TAG, Collections.unmodifiableList(statusDictList));

        //审核状态
        List<DictData> aduitDictList=new ArrayList<>();
        aduitDictList.add(new DictData(0,"已审核"));
        aduitDictList.add(new DictData(1,"未审核"));
        //可变，变为不可变
        dictMap.put(AUDIT_TAG, Collections.unmodifiableList(aduitDictList));

        //上下架状态
        List<DictData> groudDictList=new ArrayList<>();
        groudDictList.add(new DictData(0,"下架"));
        groudDictList.add(new DictData(1,"上架"));
        //可变，变为不可变
        dictMap.put(ISGROUDING_TAG, Collections.unmodifiableList(groudDictList));
    }

    /**
     * 根据键取值
     * @param key
     * @return
     */
    public static List<DictData> getByTag(String key){
        List<DictData> dictData = dictMap.get(key);
        if(dictData==null){
            throw new ServiceException(AckCode.NOT_FOUND_DATA);
        }
        return dictData;
    }

}
